package hadoop; /**
 * @author 郭天凌
 * @date 2021/11/1 13:27
 */
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;
import java.sql.SQLOutput;

public class WordCount {
//main 函数

    public String wc(String srcPath,String destPath )  throws IOException, ClassNotFoundException, InterruptedException{
        // 设置 hdfs的配置
        Configuration configuration = new Configuration();
        Job job = Job.getInstance(configuration);
        // 设置 jar包 加载路径
        job.setJarByClass(WordCount.class);
        // 设置 map和reduce 的类
        job.setMapperClass(WordCountMapper.class);
        job.setReducerClass(WordcountReduce.class);
        // 设置 map端输出
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);
        // 设置输出的类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);
        // 设置下 数据输入和数据的参数
        FileInputFormat.setInputPaths(job,new Path(srcPath));
        FileOutputFormat.setOutputPath(job,new Path(destPath));
        // 提交
        boolean result = job.waitForCompletion(true);
        System.out.println(result? 0:1);

        return "执行完毕";
    }

}
